package com.heima.article.controller;


import com.heima.article.po.ApArticle;
import com.heima.article.service.IApArticleService;
import com.heima.article.service.impl.ApArticleServiceImpl;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.vos.HotArticleVo;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 * APP已发布文章配置表 前端控制器
 * </p>
 *
 * @author lin
 * @since 2025-06-10
 */
@RestController
@RequestMapping("/api/v1/article")
@Api(value = "app端主页", tags = "app端主页")
public class ArticleHomeController {
    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ApArticleServiceImpl.class);

    @Autowired
    private IApArticleService articleService;

    /**
     * 加载文章列表
     */
    @PostMapping("/load")
    public ResponseResult<List<HotArticleVo>> load(@RequestBody ArticleHomeDto dto) {
        ResponseResult<List<HotArticleVo>> responseResult =
                articleService.load2(ArticleConstants.LOAD_TYPE_LOAD_MORE, dto, true);
        log.info("Returning articles: {}", responseResult.getData());  // 使用日志框架
        return responseResult;
    }

    /**
     * 加载更多
     */
    @PostMapping("/loadmore")
    public ResponseResult<List<HotArticleVo>> loadMore(@RequestBody ArticleHomeDto dto) {
        return articleService.load(ArticleConstants.LOAD_TYPE_LOAD_MORE, dto);
    }

    /**
     * 加载最新
     */
    @PostMapping("/loadnew")
    public ResponseResult<List<HotArticleVo>> loadNew(@RequestBody ArticleHomeDto dto) {
        return articleService.load(ArticleConstants.LOAD_TYPE_LOAD_NEW, dto);
    }

}
